package com.yyplatform.admin.platform.generator.utils;

import org.apache.commons.lang3.StringUtils;

/**
 * Created on 2024-09-23
 */
public class ColumnFieldUtils {

    public static String getFieldType(String columnType) {

        columnType = columnType.toLowerCase();

        if (StringUtils.indexOf(columnType, "varchar") != -1
                || StringUtils.indexOf(columnType, "text") != -1) {
            return "String";
        }

        if (StringUtils.equals(columnType, "tinyint(1)")) {
            return "Boolean";
        }

        if (StringUtils.indexOf(columnType, "bigint") != -1) {
            return "Long";
        }

        if (StringUtils.indexOf(columnType, "tinyint") != -1) {
            return "Integer";
        }

        if (StringUtils.indexOf(columnType, "int") != -1) {
            return "Integer";
        }

        if (StringUtils.indexOf(columnType, "datetime") != -1) {
            return "Date";
        }

        if (StringUtils.indexOf(columnType, "decimal") != -1) {
            return "BigDecimal";
        }

        if (StringUtils.indexOf(columnType, "float") != -1) {
            return "Float";
        }

        if (StringUtils.indexOf(columnType, "double") != -1) {
            return "Double";
        }

        if (StringUtils.indexOf(columnType, "date") != -1) {
            return "Date";
        }

        if (StringUtils.indexOf(columnType, "json") != -1) {
            return "String";
        }


        return "String";
    }

    public static String getFiledName(String word) {
        if (word == null) {
            return null;
        }
        String[] split = word.split("_");
        StringBuffer sb = new StringBuffer(word.length());
        for (String s : split) {
            char[] chars = s.toCharArray();
            if (chars[0] >= 'A' && chars[0] <= 'Z') {

            } else if (chars[0] >= 'a' && chars[0] <= 'z') {
                chars[0] -= 32;
            }

            sb.append(chars);
        }

        String ss = sb.toString();

        ss = ss.substring(0, 1).toLowerCase() + ss.substring(1);


        return ss;
    }

}
